import request from '@/utils/request'
import authority from '@/utils/authority'

// 获取code
export const getCode = (phone, type = 'login') => {
  return request({
    url: '/api/app/v1/phone/code',
    method: 'post',
    data: {
      type,
      phone
    }
  })
}

// 验证码登陆
export const phoneLogin = async ({ phone, code, wechat_code }) => {
  authority.clear()
  const { user, token } = await request({
    url: '/api/miniapp/v1/login',
    method: 'post',
    data: {
      phone,
      code,
      wechat_code
    }
  })
  user.token = token
  authority.set(user)
  console.log(user)
  return user
}
